﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class BezierCurveTools
{
    /// <summary>
    /// 确定 二维 中心点
    /// </summary>
    /// <param name="p1"></param>
    /// <param name="p2"></param>
    /// <param name="disRatio"></param>
    /// <param name="heightRatio"></param>
    /// <param name="angle"></param>
    /// <returns></returns>
    public static Vector3 CalculateCenterPoint( Vector3 p1, Vector3  p2, float disRatio, float heightRatio, float angle = 0)
    {
        Vector3 centerPoint = Vector3.zero;

        float distance = Vector3.Distance(p1, p2);

        Vector3 forwardDir = (p2 - p1).normalized;
        Vector3 horizontalDir = Vector3.Cross(forwardDir, Vector3.down);
        Vector3 verticalDir = Vector3.Cross(forwardDir, horizontalDir);

        Vector3 wantedDir = verticalDir * Mathf.Cos(Mathf.Deg2Rad * angle) + horizontalDir * Mathf.Sin(Mathf.Deg2Rad * angle);

        centerPoint = (distance * disRatio * forwardDir + p1) + wantedDir.normalized * distance * heightRatio;

        return centerPoint;

    }


}
